package com.itheima.controller;

import com.itheima.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@Slf4j
@RestController
public class DemoSessionController {
    @GetMapping("/s1")
    public Result s1(HttpSession session){
        log.info("session对象：" + session);

        //向session对象中存储数据
        session.setAttribute("company", "itcast");
        session.setAttribute("address", "北京");

        return Result.success();
    }

    @GetMapping("/s2")
    public Result s2(HttpSession session){
        log.info("session对象：" + session);

        //从session中获取数据
        System.out.println("company = " + session.getAttribute("company"));
        System.out.println("address = " + session.getAttribute("address"));

        return Result.success();
    }
}